import {request} from "./request";
export function getDetailsData(iid){
    return request({
        url:'/detail',
        params:{
            iid
        }
    })
}
export function getRecommend() {
    return request({
        url:'/recommend'
    })
}
//存储商品信息
export class Goods {
        constructor(itemInfo, columns, services) {
            this.images = itemInfo.topImages;
            this.title = itemInfo.title;
            this.desc = itemInfo.desc;
            this.newPrice = itemInfo.price;
            this.oldPrice = itemInfo.oldPrice;
            this.discountDesc = itemInfo.discountDesc;
            this.columns = columns;
            this.services = services;
            this.realprice = itemInfo.lowNowPrice
        }
    }
    //店铺类，存储店铺信息
export class Shop {
    constructor (shopInfo) {
        this.logo = shopInfo.shopLogo;
        this.name = shopInfo.name;
        this.fans = shopInfo.cFans;
        this.sells = shopInfo.cSells;
        this.score = shopInfo.score;
        this.goodsCount = shopInfo.cGoods;
    }
}
//商品参数
export class Params{
    constructor(info,rule) {
        this.image = info.images ? info.images[0] : '';
        this.infos = info;
        this.sizes = rule;

    }
}

//防抖函数
export  function debounce(func,delay){
    let timer = null;
    return function (...args) {
        if (timer) clearTimeout(timer);
        timer = setTimeout(() => {
            func.apply(this,args)
        },delay);
    }
}
//时间规范化
export function formatDate(date, fmt) {
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + ' ').substr(4 - RegExp.$1.length));
        let o = {
            'M+': date.getMonth() + 1,
            'd+': date.getDate(),
            'h+': date.getHours(),
            'm+': date.getMinutes(),
            'S+': date.getSeconds()
        };
        for (let k in o) {
            if (new RegExp(`(${k})`).test(fmt)) {
                let str = o[k] + '';
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
            }
        }
        return fmt;
    }
}
function padLeftZero(str) {
    return ('00' + str).substr(str.length);
}
